package com.zzyl.member.scheduled;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzyl.member.domain.pojo.Reservation;
import com.zzyl.member.mapper.SubscribeNursingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
public class AppointmentCheckTask {

    @Autowired
    private SubscribeNursingMapper subscribeNursingMapper;
    @Scheduled(cron = "0 0/15 * * * ?")
    public void checkExpired() {
        // 实际业务逻辑...
        List<Reservation> reservations = subscribeNursingMapper.selectList(Wrappers.<Reservation>lambdaQuery().eq(Reservation::getStatus, 0));
        for (Reservation reservation : reservations) {
            if( reservation.getTime().isAfter(LocalDateTime.now()))
            {
                reservation.setStatus(3);
                subscribeNursingMapper.updateById(reservation);
            }
        }
        System.out.println(" = " );
    }
}
